<template>
  <div>
    <el-row type="flex" justify="space-between">
      <el-col>
        <div style="display: flex; justify-content: space-between">
          <div>
            <el-select v-model="value" clearable placeholder="全部" @change="wwww">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <el-input
              @clear="clear"
              clearable
              v-model="form.search"
              style="width: 300px; margin-left: 15px"
              placeholder="搜索姓名、电话"
              class="input-with-select"
            >
              <el-button
                @click="searchVal"
                slot="append"
                style="
                  background-color: #45a321;
                  color: #fff;
                  border-radius: 0;
                  border: 1px solid #45a321;
                "
              >搜索</el-button>
              <i slot="prefix-icon" class="el-icon-search"></i>
            </el-input>
          </div>

          <div>
            <el-button type="primary" style="width: 100px; margin-right: 70%">导出</el-button>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-table align="center" :data="list.list" border style="width: 100%; margin: 20px 0">
      <el-table-column align="center" prop="create_time" label="咨询时间"></el-table-column>
      <el-table-column align="center" prop="type" label="咨询类型"></el-table-column>
      <el-table-column align="center" prop="name" label="咨询人"></el-table-column>
      <el-table-column align="center" prop="phone" label="电话"></el-table-column>
      <el-table-column align="center" prop="remark" label="咨询留言"></el-table-column>
      <el-table-column align="center" prop="from" label="来自">
        <template slot-scope="scope">
          <a :href="scope.row.from" target="_blank" class="ck" type="text">
            {{
              scope.row.from
            }}
          </a>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <!-- <el-button
            class="editText"
            @click="clickEdit(scope.row.id)"
            type="text"
            >查看</el-button
          >-->
          <el-button class="deletText" @click="deletUser(scope.row.id)" type="text">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="list.page"
        :page-size="list.size"
        layout="total, prev, pager, next, jumper"
        :total="parseInt(list.count)"
        align="left"
      ></el-pagination>
    </div>
    <!-- <el-table
      align="center"
      :data="signlist.list"
      border
      style="width: 100%; margin: 20px 0"
    >
          <el-table-column align="center" prop="name" label="姓名">
          </el-table-column>
          <el-table-column align="center" prop="phone" label="电话">
          </el-table-column>
      <el-table-column align="center" label="操作">
    <template slot-scope="scope">-->
    <!-- <el-button
            class="editText"
            @click="clickEdit(scope.row.id)"
            type="text"
            >查看</el-button
    >-->
    <!-- <el-button
            class="deletText"
            @click="deletUser2(scope.row.id)"
            type="text"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>-->
    <!-- <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="list.page"
        :page-size="list.size"
        layout="total, prev, pager, next, jumper"
        :total="parseInt(list.count)"
        align="left"
      ></el-pagination>
    </div>-->
  </div>
</template>

<script>
import { VUE_APP_BASE_API } from "@/config.js";
import {
  consultList,
  consultDel,
  consultInfo,
  signList,
  getAllType,
  signInfo,
  signDel,
} from "@/api/adminWeb";
import Editor from "@/components/Editor";
import activities from "./activities";
export default {
  data () {
    return {
      VUE_APP_BASE_API,
      list: [],
      signlist: [],
      activeName: 0,
      value: '',
      options: [
        {
          label: '海外智联体',
          btnActive: true,
          value: 1
        },
        {
          label: '国际维权',
          btnActive: false,
          value: 2
        }, {
          label: '优秀专利',
          btnActive: false,
          value: 3
        }, {
          btnActive: false,
          label: '优秀团队',
          value: 4
        }, {
          btnActive: false,
          label: '专利保险',
          value: 5
        },
        {
          btnActive: false,
          label: '质押融资',
          value: 6
        },
        {
          btnActive: false,
          label: '网站咨询',
          value: 7
        },
      ],
      dialogVisible: false,
      form: {
        form_consult_id: "",
        title: "",
        online_time: "",
        content: "",
        tpic: "",
        search: "",
        myorder: "",
      },
      form2: {
        form_sign_id: "",
        title: "",
        online_time: "",
        content: "",
        tpic: "",
        search: "",
        myorder: "",
      },
      contentDesc: "",
      clearDesc: 0,
      fileList: [],
    };
  },
  components: {
    Editor,
    activities,
  },
  mounted () {
    this.getLIst();
    // this.getSignLIst();
  },
  methods: {
    searchVal () {
      // this.getLIst();
      this.getSignLIst();
    },
    searchVal2 () {
      this.getSignLIst();
    },
    clickCreat () {
      this.dialogVisible = true;
    },
    async clickEdit (id) {
      try {
        this.form = await consultInfo({
          form_consult_id: id,
        });
        this.contentDesc = this.form.content;
        this.dialogVisible = true;
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    wwww () {
      this.getLIst();
    },
    deletUser (id) {
      this.$confirm("此操作将删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            await consultDel({
              form_consult_id: id,
            });
            this.getLIst();
            this.$message({
              type: "success",
              message: "删除成功",
            });
          } catch (error) {
            this.$message.error(error.message);
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    deletUser2 (id) {
      this.$confirm("此操作将删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            await signDel({
              form_sign_id: id,
            });
            this.getSignLIst();
            this.$message({
              type: "success",
              message: "删除成功",
            });
          } catch (error) {
            this.$message.error(error.message);
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    clear () {
      this.getLIst();
      this.getSignLIst();
    },
    handleClose () {
      this.clearDesc = 1;
      this.dialogVisible = false;
      this.form = {
        title: "",
        online_time: "",
        content: "",
        tpic: "",
        myorder: "",
      };
    },
    async onSuccess (response, file, fileList) {
      if (response) {
        // console.log(response.data.url);
        this.form.tpic = response.data.url;
        this.$nextTick(() => {
          this.form.tpic = response.data.url;
        });
        this.$message.success("上传成功");
      }
    },
    async getSignLIst () {
      try {
        this.signlist = await signList({
          type: 1,
          keyword: this.form.search,
        });
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    async getLIst () {
      try {
        if (this.value !== '') {
          this.list = await consultList({
            type: this.value
          });
        } else {
          this.list = await consultList();
        }
        this.list.list = this.list.list.map((item) => {
          if (item.type === 1) {
            item.type = "海外智联体";
          }
          if (item.type === 2) {
            item.type = "国际维权";
          }
          if (item.type === 3) {
            item.type = "优秀专利";
          }
          if (item.type === 4) {
            item.type = "优秀团队";
          }
          if (item.type === 5) {
            item.type = "专利保险";
          }
          if (item.type === 6) {
            item.type = "质押金融";
          }
          if (item.type === 7) {
            item.type = "网站咨询";
          }
          item.create_time = item.create_time.replace("<br>", " ");
          return { ...item };
        });
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    descVal (val) {
      this.form.content = val;
    },
    async save () {
      try {
        if (this.form.id) {
          await WebNewsEdit({
            form_consult_id: this.form.id,
            title: this.form.title,
            tpic: this.form.tpic,
            content: this.form.content,
            online_time: this.form.online_time,
            myorder: this.form.myorder,
          });
          this.getLIst();
          this.$message.success("添加成功");
          this.dialogVisible = false;
          this.clearDesc = 1;
          this.form = {
            title: "",
            online_time: "",
            content: "",
            tpic: "",
            myorder: "",
          };
        } else {
          await WebNewsAdd({
            title: this.form.title,
            tpic: this.form.tpic,
            content: this.form.content,
            online_time: this.form.online_time,
            myorder: this.form.myorder,
          });
          this.clearDesc = 1;
          this.getLIst();
          this.$message.success("添加成功");
          this.dialogVisible = false;
          this.form = {
            title: "",
            online_time: "",
            content: "",
            tpic: "",
            myorder: "",
          };
        }
      } catch (error) {
        this.$message.error(error.message);
      }
    },
    cancle () {
      this.dialogVisible = false;
      this.clearDesc = 1;
      this.form = {
        title: "",
        online_time: "",
        content: "",
        tpic: "",
        myorder: "",
      };
    },
    //每页下拉显示数据
    async handleSizeChange (size) {
      try {
        this.list = await consultList({
          keywords: this.form.search,
          page: size,
        });
      } catch (e) {
        this.$message.error(e.message);
      }
    },
    //点击第几页
    async handleCurrentChange (currentPage) {
      try {
        this.list = await consultList({
          keywords: this.form.search,
          page: currentPage,
        });
      } catch (e) {
        this.$message.error(e.message);
      }
    },
  },

};
</script>

<style lang="less" scoped>
.news_mrt {
  margin-bottom: 30px;
}
.left_w {
  width: 80%;
}
</style>